package SiTuQingYou.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import SiTuQingYou.util.DBHelper;
import SiTuQingYou.vo.City;

public class CityDao 
{
	private int s;
	private  CityDao() {}
	private static  CityDao cityd= new  CityDao();
	public static  CityDao getcityd()
	{
		return cityd;
	}
	public  ArrayList<City>  allcity() {
		
			DBHelper dbhelper = DBHelper.getDB();
		  	Connection conn = null;
			PreparedStatement ps = null;
			ResultSet rs = null; 
			
			try {
				conn = dbhelper.getConn();
				String sql = "select * from city";
				ps = conn.prepareStatement(sql);
				rs = ps.executeQuery();
				ArrayList<City> allcityid = new ArrayList<City>();
				while(rs.next()) {
					City city = new City();
					city.setId(rs.getInt("id"));
					city.setCityname(rs.getString("cityname"));
					allcityid.add(city);
				}
			  return allcityid;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			finally {
				dbhelper.close(rs, ps, conn);
			}
		return null;
	}
}
